<template>
  <a-modal
    width='618px'
    title='交付物重命名'
    cancelText="取消"
    okText="确定"
    :visible="visible"
    :confirmLoading='confirmLoading'
    @ok="handleOk"
    @cancel="handleCancel">
    <a-form>
      <a-form-item label="名称：">
        <a-input placeholder="请输入名称" class="width_509" allow-clear v-model="newName"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import {mapGetters} from 'vuex'
import {renameObj} from "@/api/fileSingle.js"
export default {
  data() {
    return {
      visible: false,
      confirmLoading: false,
      newName: '',
      renameArr: []
    }
  },
  computed: {
    ...mapGetters({
      'fileSingleData': 'fileSingle'
    })
  },
  props: {
    sessionData: {
      type: Array,
      default: () => []
    },//存入的session
  },
  methods: {
    /**
     * 重命名方法
     * 功能： 交付物重命名
     */
    handleOk() {
      console.log(this.sessionData)
      if (!this.newName) return this.$message.error('请输入名称')
      this.confirmLoading = true
      renameObj({
        identities: [{
          oid: this.sessionData[0].oid,
          name: this.newName,
          number: ''
        }]
      }).then((res) => {
        if (res && res.data.success) {
          this.confirmLoading = false
          this.$message.success(res.data.message)
          this.$emit('initTableData')
          this.visible = false
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    /**
     * 取消按钮事件
     */
    handleCancel() {
      this.visible = false
    },
    /**
     * 开启弹窗
     * key 上级需要开启那个弹窗的key props上级tree选中的tree，propsArr 上级table选中的数据
     */
    openModal(start,sessionData) {
      this.visible = start
      this.newName = sessionData[0].name;    //默认显示当前文件夹位置
    }
  }
}
</script>
<style lang="less" scoped>
.width_509 {
  width: 509px;
}
</style>